package com.bean;

import com.event.DemoEvent;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * author:houkai
 * Date: 2017/9/25
 * describe:  发布事件的地方   在开发中可以是 业务处理逻辑中发布事件
 */
public class DemoBean implements ApplicationContextAware {
    private ApplicationContext applicationContext = null;
    
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
       this.applicationContext = applicationContext;
    }

    public void addStudent(){
        System.out.println("添加");
        DemoEvent event =  new DemoEvent(applicationContext,"张三");
        applicationContext.publishEvent(event);///发布事件
    }

    public static void main(String[] args){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        DemoBean demoBean = (DemoBean)context.getBean("demoBean");
        demoBean.addStudent();
    }
    

}
